$package('Bdth.Role');
Bdth.Role = function () {
	var _box = null;
	var _this = {
		menu: $('#zTree'),
		setTreeValue: function (id) {
			var treeObj = $.fn.zTree.getZTreeObj("zTree");
			console.info(treeObj);
			var node = treeObj.getNodeByParam("id", id);
			treeObj.selectNode(node);
		},
		save: function () {
			_box.handler.save();
		},
		config: {
			event: {
				add: function () {
					//_this.clearTreeData();
					_box.handler.add();
				},
				edit: function () {
					var record = Utils.getCheckedRows();
					if (Utils.checkSelectOne(record)) {
						Bdth.progress();
						var data = {};
						var idKey = 'id'; // 主键名称
						data[idKey] = (record[0][idKey]);
						Bdth.getById('getId', data, function (result) {
							Bdth.closeProgress();
							$("#edit-win").dialog({
								href: path + '/view/role/form.html',
								width: 500,
								height: 450,
								modal: true,
								resizable: true,
							/*	collapsible: true,
								maximizable: true,*/
								onLoad: function () {
									$("#editForm").form('load', result.data);
									$("#strFuncMenu").val(result.strFuncMenu);

								},
								title: '编辑',
								buttons: [{
									text: '保存',
									iconCls: 'fa fa-save',
									btnCls: 'topjui-btn',
									handler: _box.handler.save
								}/*, {
									text: "关闭",
									iconCls: "fa fa-close",
									btnCls: "topjui-btn-danger",
									handler: _box.handler.close
								}*/],
							});

						});
					}
				},
				save: function () {
					_this.save();
				}
			},
			dataGrid: {
				title: '角色列表',
				url: 'dataList',
				columns: [[
					{field: 'id', checkbox: true, title: 'id'},
					{field: 'roleName', title: '角色名称', width: 80, sortable: true},
					{field: 'createDate', title: '创建时间', width: 120, sortable: true},
					{field: 'remark', title: '描述', width: 120, sortable: true}

				]], toolbar: [
					{id: 'btnadd', text: '添加', btnType: 'add'},
					{id: 'btnedit', text: '修改', btnType: 'edit'},
					{id: 'btndelete', text: '删除', btnType: 'remove'}
				]
			}, action: {
				add_editForm: '/view/role/form.html',
				remove: 'fakeDelete'
			},
			wid_height: {
				width: 500,
				height: 450
			},
		},
		init: function () {
			_box = new DataGrid(_this.config);
			_box.init();
		}
	}
	return _this;
}();

$(function () {
	Bdth.Role.init();
});
// Grid 工具类
var Utils = {
	getCheckedRows: function () {
		return $('#data-list').datagrid('getChecked');
	},
	checkSelect: function (rows) {// 检查grid是否有勾选的行, 有返回 true,没有返回true
		var records = rows;
		if (records && records.length > 0) {
			return true;
		}
		Bdth.alert('警告', '未选中记录.', 'messager-warning');
		return false;

	},
	checkSelectOne: function (rows) {// 检查grid是否只勾选了一行,是返回 true,否返回true
		var records = rows;
		if (!Utils.checkSelect(records)) {
			return false;
		}
		if (records.length == 1) {
			return true;
		}
		Bdth.alert('警告', '只能选择一行记录.', 'messager-error');
		return false;
	}
}